/* eslint-disable no-unused-vars */
import router from '@/router/index'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'
router.beforeEach((to, from, next) => {
  NProgress.start()
  const whiteList = ['/login', '/404']
  if (store.state.user.token) {
    if (whiteList.includes(to.path)) {
      next('/')
      NProgress.done()
    } else {
      console.log(store.getters)
      // if (Object.keys(store.state.user.userInfo).length === 0)
      if (!store.getters.userId) { store.dispatch('user/GetdashardActions') }

      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
      NProgress.done()
    }
  }
})
router.afterEach((to, from) => {
  NProgress.done()
})
